{extend name="wap/default_new/base" /}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="__TEMP__/{$style}/public/css/member_address.css">
<style>
.tips{
	font-size:16px;
	line-height:50px;
	height:50px;
	text-align:center;
	margin:200px 0px 15px;
}
.point{
	background:transparent;
	border:0px;
	color:#0080ff;
	padding:3px;
}
</style>
{/block}
{block name="goodsHead"}
<section class="head">
	<a class="head_back" onclick="window.history.go(-1)"
		href="javascript:void(0)"><i class="icon-back"></i></a>
	<div class="head-title">商家加盟</div>
</section>
{/block}
{block name="main"}
{if condition = "$apply_state eq 'apply' or $apply_state eq 'refuse_apply'"} 

<form class="form-info" {if condition = "$apply_state eq 'refuse_apply'"} style="display:none"{/if} >
	<div class="div-item">
		<span>开店身份</span>
		<select id="apply_type">
			<option value="1">个人</option>
			<option value="2">企业</option>
		</select>
	</div>
	<div class="div-item">
		<span>店铺名称</span>
		<input type="text" placeholder="请输入店铺名称" id="shop_name" />
	</div>
	
	<div class="div-item">
		<span>所属分类</span>
		<select id="shop_group_id">
			{foreach name="shop_group" item="vo"}
			<option value="{$vo.shop_group_id}" data-account-type-name="{$vo.group_name}">{$vo.group_name}</option>
			{/foreach}
		</select>
	</div>
	<div class="div-item">
		<span>店铺等级</span>
		<select id="shop_type">
			<option value="0" data-account-type-name="">请选择店铺等级</option>
			{foreach name="shop_type_list" item="vo"}
				<option value="{$vo.instance_typeid}" data-account-type-name="{$vo.type_name}">{$vo.type_name}</option>
			{/foreach}
		</select>
	</div>
	<div class="div-item">
		<span>账户类型</span>
		<select id="bank_type" onclick="bankChange(this);">
			<option value="1">银行卡</option>
			<option value="2">支付宝</option>
		</select>
	</div>
	<div class="div-item bank_info" data-flag="bank_account_name">
		<span>支行信息</span>
		<input type="text" placeholder="请输入支行信息" id="bank_account_name"/>
	</div>
	<div class="div-item" data-flag="bank_account_number">
		<span>账号信息</span>
		<input type="text" placeholder="请输入账号信息" id="bank_account_number"/>
	</div>
	<div class="div-item" data-flag="bank_real_name">
		<span>联系姓名</span>
		<input type="text" placeholder="请输入联系姓名" id="bank_real_name"/>
	</div>
	<div class="div-item" data-flag="bank_mobile">
		<span>联系电话</span>
		<input type="text" placeholder="请输入联系电话" id="bank_mobile"/>
	</div>
	
</form>
<button onclick="save()" class="btn-save">{:lang('member_preservation')}</button>
{/if}
{if condition="$apply_state eq 'is_apply'"}
	<div class="tips">
		<img src="__TEMP__/{$style}/public/images/wait.png">
		<div class="tishi">入驻申请已经提交，请等待管理员审核</div>
	</div> 
{/if}
{if condition="$apply_state eq 'is_system'"} 
	<div class="tips">
		<img src="__TEMP__/{$style}/public/images/succeed.jpg">
		<div class="tishi">您的入驻申请已被批准！您可以去电脑端商家管理中心进行查看!</div>
	</div>
{/if}
{if condition="$apply_state eq 'refuse_apply'"}
	<div class="tips error">
		<img src="__TEMP__/{$style}/public/images/false.png">
		<div class="tishi">您的入驻申请被拒！</div>
		<button class="point" onclick="replace()">重新申请入驻</button>
	</div>
	
{/if}

{/block} 
{block name="bottom"}{/block} 
{block name="javascript"}
<script type="text/javascript">
function replace(){
	$(".error").attr('style','display:none');
	$(".form-info").attr('style','dsiplay:block !important');
	$(".btn-save").attr('style','dsiplay:block !important');
}
function bankChange(event){
	var bank_type = $(event).val();
	if(bank_type == 1){
		
		$(".bank_info").show();
	} else{
		$(".bank_info").hide();
	}
}
function save(){
	var apply_type = $("#apply_type").val();
	var shop_name = $("#shop_name").val();
	var shop_group_id = $("#shop_group_id").val();
	var shop_group_name = $("#shop_group_id").text();
	var shop_type_id = $("#shop_type").val();
	var shop_type_name = $("#shop_type").text();
	var bank_type = $("#bank_type").val();
	var bank_name = $("#bank_type").text();
	var bank_account_name = $("#bank_account_name").val();
	var bank_account_number = $("#bank_account_number").val();
	var bank_real_name = $("#bank_real_name").val();
	var bank_mobile = $("#bank_mobile").val();
	
	if(shop_name==''){
		showBox('店铺名称不能为空','error');
		return false;
	}
	if(shop_group_id==''){
		showBox('请选择所属类型','error');
		return false;
	}
	if(shop_type_id <= 0){
		showBox('请选择店铺等级','error');
		return false;
	}
	return;
	if(bank_type==''){
		showBox('请选择账户类型','error');
		return false;
	}
	if(bank_account_name==''){
		showBox('支行信息不能为空','error');
		return false;
	}
	if(bank_account_number==''){
		showBox('账号信息不能为空','error');
		return false;
	}
	if(bank_real_name==''){
		showBox('联系姓名不能为空','error');
		return false;
	}
	
	if(bank_mobile==''){
		showBox('联系电话不能为空','error');
		return false;
	}
	
	if(!(/^1[3|4|5|7|8][0-9]{9}$/.test(bank_mobile))){
		showBox('请输入正确的手机号','error');
		return false;
	}
	$.ajax({
		type : "post",
		url : "{:__URL('APP_MAIN/shop/applyShop')}",
		dataType : "json",
		data : {
			"apply_type" : apply_type,
			"shop_name":shop_name,
			"shop_group_id":shop_group_id,
			"shop_group_name" : shop_group_name,
			'shop_type_id' : shop_type_id,
			"shop_type_name":shop_type_name,
			"bank_type":bank_type,
			"bank_name":bank_name,
			"bank_account_name":bank_account_name,
			"bank_account_number":bank_account_number,
			"bank_real_name":bank_real_name,
			"bank_mobile":bank_mobile
		},
		success : function(data) {
			if(data['code'] > 0){
				showBox("申请成功，请等待审核", "success");
				window.location.href=window.location.href;
			}else{
				showBox("申请失败","error");
			}
		}
	});
}
</script>
{/block}